/**
 * 获取验证码
 * @returns
 */
var hreftype=0//0发起1主页
var count = 60;
var getCaptchaForFactorytype=0;
function getCaptchaForFactory(){
	showDefault("loading","加载中...");
	var mobile = $("#mobile").val();
	var json = {}
	if(count==60){
		if(!mobile.match(/^1[34578]\d{9}$/)) {
			toast.hide();
			showDefault("fail","输入有效的手机号");
		}else{
			if(getCookie("roleId")=="10"||!getCookie("roleId")||getCookie("roleId")=="undefined"||getCookie("roleId")=="null"){
				var data= httpget(''+httpipstr+'alfa-mobile-ws/rest/user/getCaptchaForFactoryForLogin/' + mobile + '');
				toast.hide();
				if (data.status == "failure") {
					if(data.message=="4"){
						showDefault("fail","手机号不存在,请确认手机号");
					}if(data.message=="2"){
						showDefault("fail","角色收运人员,不能获取手机验证码");
					}if(data.message=="1"){
						showDefault("fail","角色收运人员,不能获取手机验证码");
					}
				} else {
					if(data.message=="3"){
						getCaptchaForFactorytype=0
					}
					if(data.message=="30"){
						getCaptchaForFactorytype=1
					}
					var countdown = setInterval(CountDown, 1000);
					function CountDown() {
						$('.send').addClass("layui-btn-disabled").css("background-color","#f1f1f1").attr('disabled',"true"); //将DIV标签隐藏。
						$('.send').css("color","#000000"); //将DIV标签隐藏。
						$('.send').html("重新发送(" + count + ")");
						if (count == 0) {
							$('.send').removeClass("layui-btn-disabled").css("background-color","#FEC61B").removeAttr("disabled"); //将DIV标签隐藏。
							$('.send').css("color","#ffffff"); //将DIV标签隐藏。
							$('.send').html("发送验证码");
							clearInterval(countdown);
						}
						count--;
					}
				}
			}else{
				toast.hide();
				showDefault("fail","收运角色已登录，无法再次登录");
			}
			
		}
	}else{
		
	}
	
}
function companylogin(){
	showDefault("loading","登录中...");
	if(getCookie("roleId")=="10"||!getCookie("roleId")||getCookie("roleId")=="undefined"||getCookie("roleId")=="null"){
		var mobile = encode64($("#mobile").val());
		var captchanum = encode64($("#captchanum").val());
		if(getCaptchaForFactorytype=="0"){
			var json = {
					"mobile": "" + mobile + "",
					"captcha": "" + captchanum + "",
					"openid":""+getCookie("openid")+"",
					"logintype":""+encode64("10")+""
				}
				setcookie("useriphone", $("#mobile").val(), 30, "/");
				$.ajax({
					cache: false,
					type: "post",
					datatype: 'json',
					contentType: 'application/json;charset=UTF-8',
					url: ''+httpipstr+'alfa-mobile-ws/rest/user/loginforweixin',
					data: JSON.stringify(json),
					success: function(data) {
						toast.hide();
						if (data.message=="7") {
							if(data.data.roleId=="10"){
								setcookie("mobiletokenuser", data.data.mobiletoken, 300, "/");
								setcookie("username", data.data.username, 300, "/");
								setcookie("realname", data.data.realname, 300, "/");
								setcookie("orgname", data.data.orgname, 300, "/");
								setcookie("userid", data.data.userId, 300, "/");
								setcookie("address", data.data.address, 300, "/");
									//触发事件
								if(hreftype==0){
									location.href="user_function.jsp"
								}else if(hreftype==1){
									location.href="user_infoList.jsp"
								}
							}else{
								showDefault("fail","您的角色不正确，无法登录");
							}
						} else {
							if(data.message=="1"){
								showDefault("fail","服务器异常，请联系管理员。");
							}else if(data.message=="2"){
								showDefault("fail","请输入手机号和验证码");
							}else if(data.message=="3"){
								showDefault("fail","验证码不正确");
							}else if(data.message=="4"){
								showDefault("fail","验证码已经超过有效时间");
							}else if(data.message=="5"){
								showDefault("fail","帐号不存在");
							}
							else if(data.message=="15"){
								showDefault("fail","您的角色不正确，无法登录");
								}else if(data.message=="10"){
									showDefault("fail","管理员审核中，请稍等");
							}
						}

					}
				});
		}else{
			toast.hide();
			var json = {
					"mobile": "" + $("#mobile").val() + "",
					"captcha": "" + $("#captchanum").val() + "",
				}
				$.ajax({
					cache: false,
					type: "post",
					datatype: 'json',
					contentType: 'application/json;charset=UTF-8',
					url: ''+httpipstr+'alfa-mobile-ws/rest/user/createUser',
					data: JSON.stringify(json),
					success: function(data) {
						if(data.message=="2"){ showDefault("fail","验证码不正确");}
						if(data.message=="4"){ showDefault("fail","账号注册成功，请保持手机畅通");getCaptchaForFactorytype=0}
						if(data.message=="5"){ showDefault("fail","注册失败");}
						if(data.message=="6"){ showDefault("fail","验证码已经超过有效时间");}
					}
				});
			
		}
	}else{
		 toast.hide();
		 showDefault("fail","收运角色已登录，无法再次登录");
	}
	
	
}